package com.tanhua.api.impl.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.api.db.UserApi;
import com.tanhua.domain.db.User;
import com.tanhua.mapper.db.UserMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    //服务方法已经在注册中心了 后期调用
    @Override
    public Long save(User user) {
        userMapper.insert(user); //mybatisPlus底层使用了主键返回策略
        return user.getId();
    }

    @Override
    public User findPhone(String phone) {
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("phone",phone);
        User user = userMapper.selectOne(qw);
        return user;
    }

    @Override
    public User findById(Integer userId) {
        User user = userMapper.selectById(userId);
        return user;
    }
    @Override
    public void updateUserPhone(User user) {
        userMapper.updateById(user);
    }
}
